home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frmListDemo
- Caption = "List Control Demo"
- ClientHeight = 4800
- ClientLeft = 2280
- ClientTop = 1650
- ClientWidth = 5760
- Height = 5265
- Left = 2190
- LinkTopic = "Form1"
- ScaleHeight = 4800
- ScaleWidth = 5760
- Top = 1275
- Width = 5940
- Begin TextBox txtSearch
- Height = 285
- Left = 240
- TabIndex = 1
- Top = 360
- Width = 5295
- End
- Begin CommandButton cmdExit
- Caption = "E&xit"
- Height = 495
- Left = 3000
- TabIndex = 8
- Top = 4080
- Width = 2535
- End
- Begin ListBox lstFonts
- Height = 1200
- Left = 240
- Sorted = -1 'True
- TabIndex = 6
- Top = 3360
- Width = 2535
- End
- Begin TextBox txtListHeadings
- BorderStyle = 0 'None
- Enabled = 0 'False
- ForeColor = &H00C00000&
- Height = 255
- Left = 240
- MultiLine = -1 'True
- TabIndex = 4
- Text = "(headings)"
- Top = 1440
- Width = 855
- End
- Begin CommandButton cmdSetColumns
- Caption = "(set columns)"
- Height = 495
- Left = 3000
- TabIndex = 7
- Top = 3480
- Width = 2535
- End
- Begin ListBox lstFruits
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1230
- Left = 240
- Sorted = -1 'True
- TabIndex = 5
- Top = 1800
- Width = 5295
- End
- Begin ComboBox cboSelect
- Height = 300
- Left = 240
- Sorted = -1 'True
- Style = 2 'Dropdown List
- TabIndex = 3
- Top = 1080
- Width = 5295
- End
- Begin Label lblSearch
- Caption = "Search:"
- Height = 255
- Left = 240
- TabIndex = 0
- Top = 120
- Width = 1455
- End
- Begin Label lblSelect
- Caption = "Select:"
- Height = 255
- Left = 240
- TabIndex = 2
- Top = 840
- Width = 1455
- End
- Option Explicit
- 'If you have questions, comments, or suggestions for
- 'improving the code presented here, please forward them
- 'to me; you're input is welcome:
- ' Brad Kaenel
- ' PC HELP-LINE
- ' 35250 Silver Leaf Circle
- ' Yucaipa, CA 92399
- ' United States
- ' CIS: 72357,3523
- ' Internet: 72357.3523@compuserve.com
- 'Although multi-column listboxes are a common
- 'requirement, they are difficult to accomplish
- 'in VB.
- 'A simple solution is to select a mono-spaced
- 'font for the listbox and align the data manually,
- 'but this is not always visually appealing. However,
- 'with a little more work you can set dynamic tabstops
- 'that will work with proportional fonts.
- 'This sample demonstrates how to set tabstops in a listbox,
- 'using a borderless, disabled text box for the column
- 'headings. It also shows how to "pre-select" a listbox
- 'or combobox item, using Windows API functions.
- Dim sFruit(10) As String, sMyFruit As String
- Dim nTabStopsSet As Integer
- Sub cboSelect_Click ()
- sMyFruit = cboSelect.Text
- txtSearch.Text = sMyFruit
- Call SelectFruit 'synchronize the listbox
- End Sub
- Sub cmdExit_Click ()
- Unload frmListDemo
- End Sub
- Sub cmdSetColumns_Click ()
- Call SetTabStops
- End Sub
- Sub Form_Load ()
- Dim nFruitCount As Integer
- 'load up some multi-column data
- txtListHeadings.Text = "Fruit" + Chr$(9) + "Opinion" + Chr$(9) + "Color"
- sFruit(1) = "Oranges" + Chr$(9) + "Good" + Chr$(9) + "Orange, of course"
- sFruit(2) = "Bananas" + Chr$(9) + "Munchy" + Chr$(9) + "Yellow"
- sFruit(3) = "Apples" + Chr$(9) + "Delicious" + Chr$(9) + "Red"
- sFruit(4) = "Blueberries" + Chr$(9) + "Nah" + Chr$(9) + "Blue"
- sFruit(5) = "Plums" + Chr$(9) + "Better than prunes" + Chr$(9) + "Purple"
- sFruit(6) = "Watermelons" + Chr$(9) + "Marvelous" + Chr$(9) + "Red and Green"
- sFruit(7) = "Cherries" + Chr$(9) + "Ummm..." + Chr$(9) + "Bright Red"
- sFruit(8) = "Mangos" + Chr$(9) + "Juicy" + Chr$(9) + "No idea"
- sFruit(9) = "Kiwis" + Chr$(9) + "Kinda weird" + Chr$(9) + "Fuzzy Green"
- sFruit(10) = "Peaches" + Chr$(9) + "OK" + Chr$(9) + "Peach, I guess(?)"
- For nFruitCount = 1 To UBound(sFruit)
- lstFruits.AddItem sFruit(nFruitCount)
- 'comboboxes don't support columns, so only use first string
- cboSelect.AddItem Left$(sFruit(nFruitCount), InStr(sFruit(nFruitCount), Chr$(9)) - 1)
- For nFruitCount = 0 To Screen.FontCount - 1
- lstFonts.AddItem Screen.Fonts(nFruitCount)
- nTabStopsSet = True
- cmdSetColumns.Value = True 'trigger tab stops
- End Sub
- Sub lstFonts_Click ()
- lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
- lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
- nTabStopsSet = Not nTabStopsSet
- cmdSetColumns.Value = True 'trigger tab stops
- End Sub
- Sub lstFruits_Click ()
- sMyFruit = lstFruits.Text
- If Len(sMyFruit) > 0 Then
- sMyFruit = Left$(sMyFruit, InStr(sMyFruit, Chr$(9)) - 1)
- txtSearch.Text = sMyFruit
- Call SelectFruit 'synchronize the combobox
- End If
- End Sub
- Sub SelectFruit ()
- If tfDULIST_SelectListItem(lstFruits, sMyFruit) Then
- If tfDULIST_SelectListItem(cboSelect, sMyFruit) Then
- End If
- End If
- End Sub
- Sub SetTabStops ()
- If nTabStopsSet Then
- If tfDULIST_SetListCols(lstFruits, txtListHeadings, False, True) Then
- cmdSetColumns.Caption = "Set &Custom Tab Stops"
- nTabStopsSet = Not nTabStopsSet
- End If
- If tfDULIST_SetListCols(lstFruits, txtListHeadings, False, False) Then
- cmdSetColumns.Caption = "Reset &Default Tab Stops"
- nTabStopsSet = Not nTabStopsSet
- End If
- End If
- End Sub
- Sub txtSearch_Change ()
- sMyFruit = txtSearch.Text
- Call SelectFruit 'synchronize the listbox and combobox
- End Sub
-